package view;

import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.util.HashSet;

import control.*;

public class SnakesCRUD extends JFrame {
  private HashSet<String> hs = new HashSet<String>();
  private CConnection connection;
  
  public SnakesCRUD() {
    super("Serpents - Create, Update, Delete");
    initComponents();
    this.setLocationRelativeTo(null);
    this.connection = new CConnection(); 
  }

  public void addCard(JPanel panel, String name) {
    this.principal.add(panel, name);
  }
  
  public void updateLayout(String card) {
    ((CardLayout)this.principal.getLayout()).show(this.principal, card);
    this.principal.validate();
  }
  
  public CConnection getConnection() {
	return this.connection;
  }
  
  private void initComponents() {
        principal = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        Feature = new javax.swing.JMenuItem();
        mnuScientificClassification = new javax.swing.JMenu();
        mniFamily = new javax.swing.JMenuItem();
        mniGenus = new javax.swing.JMenuItem();
        mniSpecie = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        principal.setLayout(new java.awt.CardLayout());

        jMenu1.setText("Colaborators");

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Member");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        
        jMenu1.add(jMenuItem3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Biologist");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);
        
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Animals");

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Serpent");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        
        jMenu2.add(jMenuItem5);
        
        jMenuBar1.add(jMenu2);

        jMenu3.setText("Others");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("States");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Colors");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem2);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("Regions");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        Feature.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        Feature.setText("Feature");
        Feature.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FeatureActionPerformed(evt);
            }
        });
        jMenu3.add(Feature);
        
        jMenuBar1.add(jMenu3);

        mnuScientificClassification.setText("Scientific Classification");

        mniFamily.setText("Family");
        mniFamily.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniFamilyActionPerformed(evt);
            }
        });
        mnuScientificClassification.add(mniFamily);

        mniGenus.setText("Genus");
        mniGenus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniGenusActionPerformed(evt);
            }
        });
        mnuScientificClassification.add(mniGenus);
        
        mniSpecie.setText("Specie");
        mniSpecie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniSpecieActionPerformed(evt);
            }
        });
        mnuScientificClassification.add(mniSpecie);

        jMenuBar1.add(mnuScientificClassification);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(principal, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(principal, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
        );

        pack();
        this.setSize(819, 465);
  }

  private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
    if (!hs.contains(NewState.NAME)) {
      NewState ns = new NewState(this);
      this.addCard(ns, NewState.NAME);
      this.hs.add(NewState.NAME);
    }
    
    this.updateLayout(NewState.NAME);
  }

  private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
    if (!hs.contains(NewColor.NAME)) {
      NewColor nc = new NewColor(this);
      this.addCard(nc, NewColor.NAME);
      this.hs.add(NewColor.NAME);
    }
    
    this.updateLayout(NewColor.NAME);
  }
  
  private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
    if (!hs.contains(NewMember.NAME)) {
      NewMember nm = new NewMember(this);
      this.addCard(nm, NewMember.NAME);
      this.hs.add(NewMember.NAME);
    }
    
    this.updateLayout(NewMember.NAME);
  }
  
  private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
    if (!hs.contains(NewBiologist.NAME)) {
      NewBiologist ns = new NewBiologist(this);
      this.addCard(ns, NewBiologist.NAME);
      this.hs.add(NewBiologist.NAME);
    }
    
    this.updateLayout(NewBiologist.NAME);
  }
  
  private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {
    /*if (!hs.contains(NewSerpent.NAME)) {
	  NewSerpent ns = new NewSerpent(this);
	  this.addCard(ns, NewSerpent.NAME);
	  this.hs.add(NewSerpent.NAME);
	}
	
	this.updateLayout(NewSerpent.NAME);*/
  }
  
  private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
    /*if (!hs.contains(NewRegion.NAME)) {
	  NewRegion ns = new NewRegion(this);
	  this.addCard(ns, NewRegion.NAME);
	  this.hs.add(NewRegion.NAME);
	}
	    
	this.updateLayout(NewRegion.NAME);*/
  }
  
  private void FeatureActionPerformed(java.awt.event.ActionEvent evt) {
	    /*if (!hs.contains(NewRegion.NAME)) {
		  NewRegion ns = new NewRegion(this);
		  this.addCard(ns, NewRegion.NAME);
		  this.hs.add(NewRegion.NAME);
		}
		    
		this.updateLayout(NewRegion.NAME);*/
	  }

  private void mniFamilyActionPerformed(java.awt.event.ActionEvent evt) {
	  if (!hs.contains(NewFamily.NAME)) {
		  NewFamily nm = new NewFamily(this);
	      this.addCard(nm, NewFamily.NAME);
	      this.hs.add(NewFamily.NAME);
	    }
	    
	    this.updateLayout(NewFamily.NAME);
  }
  
  private void mniGenusActionPerformed(java.awt.event.ActionEvent evt) {
	  if (!hs.contains(NewGenus.NAME)) {
		  NewGenus nm = new NewGenus(this);
	      this.addCard(nm, NewGenus.NAME);
	      this.hs.add(NewGenus.NAME);
	    }
	    
	    this.updateLayout(NewGenus.NAME);
  }

  private void mniSpecieActionPerformed(java.awt.event.ActionEvent evt) {
	  if (!hs.contains(NewSpecie.NAME)) {
		  NewSpecie nm = new NewSpecie(this);
	      this.addCard(nm, NewSpecie.NAME);
	      this.hs.add(NewSpecie.NAME);
	    }
	    
	    this.updateLayout(NewSpecie.NAME);
  }


  public static void main(String args[]) {
    try {
      javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(null, ex.getMessage());
    }
    
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        new SnakesCRUD().setVisible(true);
      }
    });
  }
  
  private javax.swing.JMenuItem Feature;
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenu jMenu2;
  private javax.swing.JMenu jMenu3;
  private javax.swing.JMenuBar jMenuBar1;
  private javax.swing.JMenuItem jMenuItem1;
  private javax.swing.JMenuItem jMenuItem2;
  private javax.swing.JMenuItem jMenuItem3;
  private javax.swing.JMenuItem jMenuItem4;
  private javax.swing.JMenuItem jMenuItem5;
  private javax.swing.JMenuItem jMenuItem6;
  private javax.swing.JMenuItem mniFamily;
  private javax.swing.JMenuItem mniGenus;
  private javax.swing.JMenuItem mniSpecie;
  private javax.swing.JMenu mnuScientificClassification;
  private javax.swing.JPanel principal;
}